package com.uchedao.mybaselibrary.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.uchedao.mybaselibrary.R;
import com.uchedao.mybaselibrary.view.dialog_for_ios.ZAlertDialog;

/**
 * 网络工具
 * Created by zhengxizhen on 15/8/17.
 */
public class NetUtil {

    /**
     * 判断网络状态是否已链接
     */
    public static boolean isNet(final Context context) {

        boolean result = MachineUtil.isNetWorkStatus(context);
        if (!result) {
            // 提示是否前往设置网络链接
            AlertDialog alertDialog = new ZAlertDialog.Builder(context)
                    .setTitle(context.getString(R.string.toast))
                    .setMessage(context.getString(R.string.no_net))
                    .setPositiveButton(context.getString(R.string.yes), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            MachineUtil.goToSetNetwork(((Activity) context));
                        }
                    })
                    .setNegativeButton(context.getString(R.string.no), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).create();
            alertDialog.show();
        }

        return result;
    }
}
